<template>
	<view class="changeSex">
		<view class="cs_item">
			<view class="item" :class="{ b_solid: index == 0 }" v-for="(item, index) in sexList" :key="index" @click="clickSex(item, index)">
				<text>{{ item.text }}</text>
				<image v-if="item.id == currID" src="../../../static/xs_icon/choseSel.png" mode=""></image>
				<image v-else src="../../../static/xs_icon/chose1.png" mode=""></image>
			</view>
			<!-- <view class="item">
				<text>女</text>
				<image src="../../../static/xs_icon/chose1.png" mode=""></image>
			</view> -->
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			sexList: [{ text: '男', id: 1 }, { text: '女', id: 2 }],
			currID: 0
		};
	},
	onLoad(e) {
		this.currID = e.sexCode;
		console.log(uni.getStorageSync('USER_INFO'));
	},
	created() {
		// console.log(this.letterList.length)
	},
	methods: {
		// 选择性别
		clickSex(item, index) {
			this.currID = item.id;
		},
		// 修改个人信息
		modifyPersonalData() {
			this.$popup.showLoading();
			const USER_INFO = uni.getStorageSync('USER_INFO');
			const data = {
				sex: this.currID,
				head_img: USER_INFO.head_img,
				user_nickname: USER_INFO.user_nickname
			};
			this.$api
				.post(global.apiUrls.modifyPersonalData, data)
				.then(res => {
					// console.log(user);
					uni.hideLoading();
					const user = res.data.data;
					if (res.data.code == 1) {
						uni.setStorageSync('USER_INFO', user.userinfo);
						this.$message.info('修改成功');
						setTimeout(() => {
							uni.navigateBack();
						}, 1000);
					}
				})
				.catch(err => {
					// this.$popup.showToast('保存失败')
				});
		}
	},
	onNavigationBarButtonTap(e) {
		console.log('按钮点击事件');
		this.modifyPersonalData();
	}
};
</script>

<style lang="scss">
page {
	background-color: #f2f3f4;
}
.changeSex {
	background-color: #fff;
	.cs_item {
		padding: 0 36upx;
		.item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 52upx 0;
			text {
				font-size: 32upx;
				color: #333333;
			}
			image {
				width: 36upx;
				height: 36upx;
			}
		}
		.b_solid {
			border-bottom: 1px solid #eee;
		}
	}
}
</style>
